
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0034
 * @Author : WangRuoyu 
 * @Date : 2023/5/24 14:25
 */

#include "iostream"
#include "vector"

using namespace std;

class Solution {
public:
    vector<int> searchRange(vector<int> &nums, int target) {
        vector<int> res = {-1, -1};

        if (!nums.size()) return res;

        int l = 0;
        int r = nums.size() - 1;

        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= target) r = mid;
            else l = mid + 1;
        }

        if (nums[l] != target) {
            return res;
        } else {
            res[0] = l;
        }

        r = nums.size() - 1;

        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (nums[mid] <= target) l = mid;
            else r = mid - 1;
        }

        res[1] = l;

        return res;
    }
};


int main() {
    Solution sl;
    vector<int> a = {5, 7, 7, 8, 8, 10};
    vector<int> res = sl.searchRange(a, 8);
    for (int i: res) {
        printf("%d ", i);
    }
    return 0;
}


